#include "context_widget.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QContextMenuEvent>
#include <QDebug>

ContextWidget::ContextWidget(QWidget *parent)
	: QWidget{parent}
{
	initAction();
	menu = new QMenu();

	menu->addAction(copy);
	menu->addAction(paste);
}

void ContextWidget::initAction()
{
	copy = new QAction("复制");
	paste = new QAction("粘贴");
	connect(copy, &QAction::triggered, this, &ContextWidget::copy_slot);
	connect(paste, &QAction::triggered, this, &ContextWidget::paste_slot);
}

void ContextWidget::copy_slot()
{
	//QAction * act = (QAction *)sender();
	qDebug() << "复制";
}

void ContextWidget::paste_slot()
{
	qDebug() << "粘贴";
}

void ContextWidget::contextMenuEvent(QContextMenuEvent *event)
{
	//menu = new QMenu();

	//menu->addAction(copy);
	//menu->addAction(paste);

	menu->exec(event->globalPos());
}
